/*****************************************************************************
 *   Copyright (C) 2008 John Schember <john@nachtimwald.com>                 *
 *                                                                           *
 *   This file is part of niwbillmanager.                                    *
 *                                                                           *
 *   niwbillmanager is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as          *
 *   published by the Free Software Foundation, either version 3 of the      *
 *   License, or (at your option) any later version.                         *
 *                                                                           *
 *   niwbillmanager is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with niwbillmanager. If not, see                                  *
 *   <http://www.gnu.org/licenses/>.                                         *
 *****************************************************************************/

#include <QStringList>

#include "settingsmanager.h"

SettingsManager::SettingsManager()
{
    m_duePastColor = value("mainwindow/duepastcolor",
        QColor(Qt::red)).value<QColor>();
    m_dueTodayColor = value("mainwindow/duetodaycolor",
        QColor(Qt::darkYellow)).value<QColor>();
    m_dueWeekColor = value("mainwindow/dueweekcolor",
        QColor(Qt::darkGreen)).value<QColor>();
    m_currencySymbol = value("mainwindow/currencysymbol", tr("$")).toString();
}

QPoint SettingsManager::getMainWindowPosition()
{
    return value("mainwindow/position", QPoint(0, 0)).toPoint();
}

QSize SettingsManager::getMainWindowSize()
{
    return value("mainwindow/size", QSize(593, 499)).toSize();
}

QByteArray SettingsManager::getMainWindowState()
{
    return value("mainwindow/state").toByteArray();
}

bool SettingsManager::isMainWindowToolbarVisible()
{
    return value("mainwindow/toolbar-visible", true).toBool();
}

Qt::ToolButtonStyle SettingsManager::getMainWindowToolbarButtonStyle()
{
    if (value("mainwindow/toolbar-buttonstyle",
        "textundericon").toString().toLower() == "textundericon")
    {
        return Qt::ToolButtonTextUnderIcon;
    }
    else {
        return Qt::ToolButtonIconOnly;
    }
}

QByteArray SettingsManager::getMainWindowHSplitterState()
{
    return value("mainwindow/hsplitter-state").toByteArray();
}

QByteArray SettingsManager::getMainWindowVSplitterState()
{
    return value("mainwindow/vsplitter-state").toByteArray();
}

QByteArray SettingsManager::getMainWindowItemListHeaderState()
{
    return value("mainwindow/itemlist-state").toByteArray();
}

QColor SettingsManager::getMainWindowDuePastColor()
{
    return m_duePastColor;
}

QColor SettingsManager::getMainWindowDueTodayColor()
{
    return m_dueTodayColor;
}

QColor SettingsManager::getMainWindowDueWeekColor()
{
    return m_dueWeekColor;
}

QString SettingsManager::getMainWindowCurrencySymbol()
{
    return m_currencySymbol;
}

QString SettingsManager::getBackendCurrent()
{
    return value("backend/current").toString();
}

QSet<QString> SettingsManager::getPluginsEnabled()
{
    return value("plugins/enabled").toStringList().toSet();
}

void SettingsManager::setMainWindowPosition(QPoint position)
{
    setValue("mainwindow/position", position);
}

void SettingsManager::setMainWindowSize(QSize size)
{
    setValue("mainwindow/size", size);
}

void SettingsManager::setMainWindowState(QByteArray state)
{
    setValue("mainwindow/state", state);
}

void SettingsManager::setMainWindowToolbarVisible(bool isVisible)
{
    setValue("mainwindow/toolbar-visible", isVisible);
}

void SettingsManager::setMainWindowToolbarButtonStyle(Qt::ToolButtonStyle
    style)
{
    if (style == Qt::ToolButtonTextUnderIcon) {
        setValue("mainwindow/toolbar-buttonstyle",
            "textundericon");
    }
    else {
        setValue("mainwindow/toolbar-buttonStyle", "icon");
    }
}

void SettingsManager::setMainWindowHSplitterState(QByteArray state)
{
    setValue("mainwindow/hsplitter-state", state);
}

void SettingsManager::setMainWindowVSplitterState(QByteArray state)
{
    setValue("mainwindow/vsplitter-state", state);
}

void SettingsManager::setMainWindowItemlistHeaderState(QByteArray state)
{
    setValue("mainwindow/itemlist-state", state);
}

void SettingsManager::setMainWindowDuePastColor(QColor color)
{
    m_duePastColor = color;
    setValue("mainwindow/duepastcolor", color);
}

void SettingsManager::setMainWindowDueTodayColor(QColor color)
{
    m_dueTodayColor = color;
    setValue("mainwindow/duetodaycolor", color);
}

void SettingsManager::setMainWindowDueWeekColor(QColor color)
{
    m_dueWeekColor = color;
    setValue("mainwindow/dueweekcolor", color);
}

void SettingsManager::setMainWindowCurrencySymbol(QString symbol)
{
    m_currencySymbol = symbol;
    setValue("mainwindow/currencysymbol", symbol);
}

void SettingsManager::setBackendCurrent(QString backendName)
{
    setValue("backend/current", backendName);
}

void SettingsManager::setPluginsEnabled(QSet<QString> plugins)
{
    setValue("plugins/enabled", (QStringList)plugins.toList());
}
